package com.own.business.wechat.mobile.controller;

import com.own.aop.login.LoginIgnore;
import com.own.business.wechat.mobile.util.WechatMobileUtil;
import com.own.component.common.base.controller.BaseController;
import com.own.component.common.model.R;
import com.own.component.common.model.ResultModel;
import com.own.component.log.operation.aop.LogOperationAop;
import com.own.constant.ConstantApiPrefix;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * WechatMobileUserController
 *
 * @author chenxueli
 * @date 2023-06-30 10:39:05
 */
@Slf4j
@Tag(name = "微信移动应用用户" + ConstantBeanSuffix.CONTROLLER)
@RestController
@RequestMapping(ConstantApiPrefix.BASE_API_V1_PREFIX + "wechat/mobile/user")
public class WechatMobileUserController extends BaseController {

    @Resource
    private WechatMobileUtil wechatMobileUtil;

    @LoginIgnore
    @LogOperationAop
    @Operation(summary = "根据code获取openId")
    @GetMapping(value = "/openId/{code}")
    public ResultModel<String> openId(
            @Parameter(description = "微信小程序code", required = true) @PathVariable String code
    ) {
        // 获取openId
        var openId = wechatMobileUtil.getOpenId(code);
        // 获取用户信息
        wechatMobileUtil.getUserInfo(openId);
        return R.success(openId);
    }

}
